home *** CD-ROM | disk | FTP | other *** search
- /* FILE: Demo_main.c */
- #include "Demo.h"
-
- DialogPtr dlogW;
- ControlHandle ctlH[3];
- Rect uiRect[2];
- int pageNo = 1;
- Boolean a_Boolean;
- int a_int;
- long a_long;
- float a_float;
- short double a_shortDbl;
- double a_double;
- Str255 a_Str255;
-
- pascal void DrawUserItem(theDlog, theItem)
- DialogPtr theDlog;
- int theItem;
- {
- if (theItem == 5)
- DrawPage(); /* defined in Demo_draw.c */
- else /* theItem must == 6 since there're only 2 userItems */
- FillRect(&uiRect[1], black); /* draw the separating line */
- }
-
- SetupDialog()
- {
- auto int n, itemType;
- auto Rect itemBox;
- auto Handle itemHandle;
-
- /* Attempt to make the modeless dialog in the heap */
- if (dlogW = GetNewDialog(512, NIL, -1L)) {
- /* Fetch & Stash the userItem display Rects
- & the ShowVars, Previous and Next Button
- ContolHandles. We'll need them for drawing the
- userItems and buttons. Also, install UserItems...
- */
- for (n = 2; n <= 6; ++n) {
- GetDItem(dlogW, n, &itemType, &itemHandle, &itemBox);
- switch (n) {
- case 2: /* ShowVars Button */
- case 3: /* Previous Button */
- case 4: /* Next Button */
- ctlH[n-2] = (ControlHandle) itemHandle;
- break;
- case 5: /* Page Display -- UserItem */
- case 6: /* Separating Line -- UserItem */
- uiRect[n-5] = itemBox;
- /* Install the Drawing Procedure for the UserItems */
- SetDItem(dlogW, n, itemType, DrawUserItem, &itemBox);
- break;
- }
- }
- /* Disable the ShowVars and Previous Buttons */
- HiliteControl(ctlH[SHOW_BUT], DISABLE);
- HiliteControl(ctlH[PREV_BUT], DISABLE);
- }
- else {
- ShowVars(1, NIL, PSTR, "\pGetNewDialog() failed...");
- ExitToShell();
- }
- }
-
- main()
- {
- auto EventRecord eventRec;
- auto WindowPtr frontW;
- auto DialogPtr theDlog;
- auto int itemHit;
- auto Boolean terminated = FALSE;
-
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NIL);
- FlushEvents(everyEvent, NL1);
- SetupDialog();
- ShowWindow(dlogW);
- SetPort(dlogW);
- InitCursor();
- while (!terminated) {
- if (!GetNextEvent(everyEvent, &eventRec))
- continue;
- if (!IsDialogEvent(&eventRec))
- continue;
- if (!DialogSelect(&eventRec, &theDlog, &itemHit))
- continue;
- if (theDlog != dlogW)
- continue;
- switch (itemHit) {
- case 1: /* Quit Button Hit */
- terminated = TRUE;
- break;
- case 2: /* ShowVars Button Hit -- do it! */
- /* Set some value to look at... */
- a_Boolean = TRUE;
- a_int = 101;
- a_long = 10101;
- a_float = -12.21;
- a_shortDbl = 654321.123;
- a_double = -987654321.123456;
- PStrCopy("\pThis is a pascal string.", 1, ALL, a_Str255);
- ShowVars(7, "\pa_Boolean", BOOL, &a_Boolean,
- "\pa_int", CINT, &a_int,
- "\pa_long", CLONG, &a_long,
- "\pa_float", CFLOAT, &a_float,
- "\pa_shortDbl", CSHORTDBL, &a_shortDbl,
- "\pa_double", CDBL, &a_double,
- "\pa_Str255", PSTR, a_Str255);
- break;
- case 3: /* Previous Button Hit -- adjust pageNo */
- if (--pageNo == FIRST_PAGE)
- HiliteControl(ctlH[PREV_BUT], DISABLE);
- if (pageNo == LAST_PAGE - 1)
- HiliteControl(ctlH[NEXT_BUT], ENABLE);
- InvalRect(&dlogW->portRect); /* force update */
- break;
- case 4: /* Next Button Hit -- adjust pageNo */
- if (++pageNo == FIRST_PAGE + 1)
- HiliteControl(ctlH[PREV_BUT], ENABLE);
- if (pageNo == LAST_PAGE)
- HiliteControl(ctlH[NEXT_BUT], DISABLE);
- InvalRect(&dlogW->portRect); /* force update */
- break;
- }
- HiliteControl(ctlH[SHOW_BUT], (pageNo == SV_PAGE ? ENABLE : DISABLE));
- }
- DisposDialog(dlogW);
- }
-